package com.zhuchaooasystem.adapter.holder;

import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.util.SparseBooleanArray;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jude.easyrecyclerview.EasyRecyclerView;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.zhuchaooasystem.R;
import com.zhuchaooasystem.entity.DailyEntity;
import com.zhuchaooasystem.widget.ExpandableTextView;

import static android.view.View.GONE;
import static android.view.View.VISIBLE;

/**
 * @author yinsi
 */
public class DailyListHolder extends BaseViewHolder<DailyEntity.ResultBean.SuccessfulBean> {
    private final int num_column = 3;
    //----
    private TextView txt_name;
    private TextView txt_time;
    private ExpandableTextView expandtxt_content;
    private EasyRecyclerView recycle_images;
    //----
    private Context mContext;

    public DailyListHolder(ViewGroup parent) {
        super(parent, R.layout.item_activity_daily);
        mContext = getContext();
        //----
        txt_name = $(R.id.item_act_daily_txt_name);
        txt_time = $(R.id.item_act_daily_txt_time);
        expandtxt_content = $(R.id.item_act_daily_expandtxt_content);
        recycle_images = $(R.id.item_act_daily_recycle);
    }

    @Override
    public void setData(final DailyEntity.ResultBean.SuccessfulBean daily) {

        txt_name.setText(daily.getUserName());
        txt_time.setText(daily.getServeiceTime());
        String content = daily.getContenctMessage().toString();
        if (content.contains("\r")) {
            content = content.replace("\r", "\n");
        }
        expandtxt_content.setText(content, new SparseBooleanArray(), getDataPosition());
        if (null != daily.getArryImg() && daily.getArryImg().size() > 0) {
            recycle_images.setVisibility(VISIBLE);
            //----
            recycle_images.setLayoutManager(new GridLayoutManager(mContext, num_column));
            recycle_images.setAdapterWithProgress(new RecyclerArrayAdapter<DailyEntity.ResultBean.SuccessfulBean.ArryImgBean>(mContext, daily.getArryImg()) {

                @Override
                public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
                    return new DailyImageListHolder(parent, daily.getArryImg(),num_column);
                }
            });
        } else {
            recycle_images.setVisibility(GONE);
        }
    }

}
